package com.restaurant.application.indexes.consumptionlist.support;

import com.google.common.collect.Lists;
import com.nebutown.commonunits.dataface.definitions.TableData;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;

public class ConsumptionListPageData implements PickableBean {

    public static final String FN_TABLEDATA = "tableData";
    public static final String FN_DOSEARCHPATH = "doSearchPath";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
             FN_TABLEDATA,
             FN_DOSEARCHPATH);

    private TableData tableData;
    private String doSearchPath;

    public ConsumptionListPageData(TableData tableData, String doSearchPath) {
        setTableData(tableData);
        setDoSearchPath(doSearchPath);
    }

    public ConsumptionListPageData() {
    }

    public ConsumptionListPageData duplicate() {
        ConsumptionListPageData result = new ConsumptionListPageData();
        result.tableData = this.tableData == null ? null : this.tableData.duplicate();
        result.doSearchPath = this.doSearchPath;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public TableData getTableData() {
        return tableData;
    }

    public void  setTableData(TableData value) {
        this.tableData = value;
    }

    public ConsumptionListPageData withTableData(TableData value) {
        setTableData(value);
        return this;
    }

    public ConsumptionListPageData withTableData(TableData value, TableData defaultValue) {
        setTableData(value == null ? defaultValue : value);
        return this;
    }

    public String getDoSearchPath() {
        return doSearchPath;
    }

    public void  setDoSearchPath(String value) {
        this.doSearchPath = value;
    }

    public ConsumptionListPageData withDoSearchPath(String value) {
        setDoSearchPath(value);
        return this;
    }

    public ConsumptionListPageData withDoSearchPath(String value, String defaultValue) {
        setDoSearchPath(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch(name) {
        case "tableData": return getTableData();
        case "doSearchPath": return getDoSearchPath();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if(!(o instanceof ConsumptionListPageData)) return false;
        return signature().equals(((ConsumptionListPageData)o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean ConsumptionListPageData has no signature defined, no hash code or equals possible.");
    }
}
